package com.zego.wawaji.ui.rank.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 充值奖品
 * Created by Su on 2018/1/15.
 */
public class Award extends BaseData implements Parcelable {
    private long id;
    private int aid;   // 活动id
    private int rank;
    private long tid;   // 内部物流号
    private String awardName;  // 奖品名
    private int awardType;  // 奖品类型   1 发货型商品， 2 虚拟型商品  -1 其他型商品
    private String awardImg;    // 奖品图片
    private String awardRemark;    // 奖品描述
    private String countTime;
    private int orderStatus;         // 订单状态
    private String remark;    // 商品说明
    private String updateTime; //更新时间

    // ==== 功能字段，无需解析 ============
    private boolean isChoose = false;

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.id = jsonObject.optLong("Id");
        this.aid = jsonObject.optInt("Aid");
        this.rank = jsonObject.optInt("Rank");
        this.tid = jsonObject.optLong("Tid");
        this.awardName = jsonObject.optString("GoodsTitle");
        this.awardType = jsonObject.optInt("GoodsType");
        this.awardImg = jsonObject.optString("GoodsImg");
        this.awardRemark = jsonObject.optString("GoodsRemark");
        this.countTime = jsonObject.optString("CountTime");
        this.orderStatus = jsonObject.optInt("OrderStatus");
        this.remark = jsonObject.optString("Remark");
        this.updateTime = jsonObject.optString("UpdateTime");
    }

    public boolean isChoose() {
        return isChoose;
    }

    public void setChoose(boolean choose) {
        isChoose = choose;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public String getRemark() {
        return remark;
    }

    public int getOrderStatus() {
        return orderStatus;
    }

    public String getCountTime() {
        return countTime;
    }

    public String getAwardRemark() {
        return awardRemark;
    }

    public long getId() {
        return id;
    }

    public int getAid() {
        return aid;
    }

    public int getRank() {
        return rank;
    }

    public long getTid() {
        return tid;
    }

    public int getAwardType() {
        return awardType;
    }

    public String getAwardName() {
        return awardName;
    }

    public String getAwardImg() {
        return awardImg;
    }

    public Award() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeInt(this.aid);
        dest.writeInt(this.rank);
        dest.writeLong(this.tid);
        dest.writeString(this.awardName);
        dest.writeInt(this.awardType);
        dest.writeString(this.awardImg);
        dest.writeString(this.awardRemark);
        dest.writeString(this.countTime);
        dest.writeInt(this.orderStatus);
        dest.writeString(this.remark);
        dest.writeString(this.updateTime);
        dest.writeByte(this.isChoose ? (byte) 1 : (byte) 0);
    }

    protected Award(Parcel in) {
        this.id = in.readLong();
        this.aid = in.readInt();
        this.rank = in.readInt();
        this.tid = in.readLong();
        this.awardName = in.readString();
        this.awardType = in.readInt();
        this.awardImg = in.readString();
        this.awardRemark = in.readString();
        this.countTime = in.readString();
        this.orderStatus = in.readInt();
        this.remark = in.readString();
        this.updateTime = in.readString();
        this.isChoose = in.readByte() != 0;
    }

    public static final Creator<Award> CREATOR = new Creator<Award>() {
        @Override
        public Award createFromParcel(Parcel source) {
            return new Award(source);
        }

        @Override
        public Award[] newArray(int size) {
            return new Award[size];
        }
    };
}
